package com.ruoyi.channel.service.impl;

import java.util.List;

import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.check.CheckEmptyUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.channel.mapper.ChannelMerchantsMapper;
import com.ruoyi.channel.domain.ChannelMerchants;
import com.ruoyi.channel.service.IChannelMerchantsService;

/**
 * 渠道商数据Service业务层处理
 *
 * @author ruoyi
 * @date 2025-04-09
 */
@Service
public class ChannelMerchantsServiceImpl implements IChannelMerchantsService {
    @Autowired
    private ChannelMerchantsMapper channelMerchantsMapper;

    /**
     * 查询渠道商数据
     *
     * @param id 渠道商数据主键
     * @return 渠道商数据
     */
    @Override
    public ChannelMerchants selectChannelMerchantsById(Long id) {
        return channelMerchantsMapper.selectChannelMerchantsById(id);
    }

    /**
     * 查询渠道商数据列表
     *
     * @param channelMerchants 渠道商数据
     * @return 渠道商数据
     */
    @Override
    public List<ChannelMerchants> selectChannelMerchantsList(ChannelMerchants channelMerchants) {
        return channelMerchantsMapper.selectChannelMerchantsList(channelMerchants);
    }

    /**
     * 新增渠道商数据
     *
     * @param channelMerchants 渠道商数据
     * @return 结果
     */
    @Override
    public int insertChannelMerchants(ChannelMerchants channelMerchants) {
        channelMerchants.setCreateTime(DateUtils.getNowDate());
        return channelMerchantsMapper.insertChannelMerchants(channelMerchants);
    }

    /**
     * 修改渠道商数据
     *
     * @param channelMerchants 渠道商数据
     * @return 结果
     */
    @Override
    public int updateChannelMerchants(ChannelMerchants channelMerchants) {
        channelMerchants.setUpdateTime(DateUtils.getNowDate());
        return channelMerchantsMapper.updateChannelMerchants(channelMerchants);
    }

    /**
     * 批量删除渠道商数据
     *
     * @param ids 需要删除的渠道商数据主键
     * @return 结果
     */
    @Override
    public int deleteChannelMerchantsByIds(Long[] ids) {
        if (!CheckEmptyUtil.isEmpty(ids)){
            for (Long id : ids) {
                ChannelMerchants channelMerchants = channelMerchantsMapper.selectChannelMerchantsById(id);
                channelMerchantsMapper.updateUserType(channelMerchants.getUserId());
            }
        }
        return channelMerchantsMapper.deleteChannelMerchantsByIds(ids);
    }

    /**
     * 删除渠道商数据信息
     *
     * @param id 渠道商数据主键
     * @return 结果
     */
    @Override
    public int deleteChannelMerchantsById(Long id) {
        return channelMerchantsMapper.deleteChannelMerchantsById(id);
    }
}
